<?php
/**
 * File adapter for Designer_Storage
 * @author Kirill A Egorov 2012
 */
class Designer_Storage_Adapter_File extends Designer_Storage_Adapter_Abstract
{
	static protected $_configPath = '';
	/**
	 * (non-PHPdoc)
	 * @see Designer_Storage_Adapter_Abstract::load()
	 */
	public function load($id)
	{
		$id = self::$_configPath . $id;
		if(!is_file($id))
			throw new Exception('Invalid file path');
		return $this->_unpack(file_get_contents($id));
	}

	/**
	 * (non-PHPdoc)
	 * @see Designer_Storage_Adapter_Abstract::save()
	 */
	public function save($id , Designer_Project $obj)
	{
		$id = self::$_configPath . $id;
		$result = @file_put_contents($id , $this->_pack($obj));
		if($result!==false)
			return true;
		else 
			return false;
	}

	/**
	 * (non-PHPdoc)
	 * @see Designer_Storage_Adapter_Abstract::delete()
	 */
	public function delete($id)
	{
		$id = self::$_configPath . $id;
		return unlink($id);
	}
	/**
	 * Set path to configs directory
	 * @param string $path
	 */
	static public function setConfigsPath($path){
		self::$_configPath = $path;
	}
}